﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace EpiMapit.Test
{
    [TestClass]
    public class CurveUrlGeneratorFixture
    {
        private ICollection<CaseSet> caseSets;
        private CurveUrlGenerator generator;

        [TestInitialize()]
        public void TestInitialize()
        {
            caseSets = new List<CaseSet>();
            generator = new CurveUrlGenerator();
        }

        [TestMethod]
        public void TestEmptyCasesList()
        {

            int x;
            var result = CurveUrlGenerator.GetCurveChartUrl(100, 100, caseSets, "type", out x);
            var expected = "http://chart.apis.google.com/chart?cht=lxy&chs=100x100&chm=s,00FF00,0,-1,5&chd=t:";

            Assert.AreEqual(expected, result, "Url does not match");
        }

        [TestMethod]
        public void TestEmptyFilteredCases()
        {
            CaseSet cs1 = new CaseSet();
            cs1.Levels.Add("type1", 1);
            cs1.Levels.Add("type2", 2);
            cs1.Levels.Add("type3", 3);

            CaseSet cs2 = new CaseSet();
            cs2.Levels.Add("type2", 1);
            cs2.Levels.Add("type3", 2);
            cs2.Levels.Add("type4", 3);

            CaseSet cs3 = new CaseSet();
            cs3.Levels.Add("type4", 4);
            cs3.Levels.Add("type5", 5);
            cs3.Levels.Add("type6", 6);

            caseSets.Add(cs1);
            caseSets.Add(cs2);
            caseSets.Add(cs3);

            int x;
            var result = CurveUrlGenerator.GetCurveChartUrl(100, 100, caseSets, "type", out x);
            var expected = "http://chart.apis.google.com/chart?cht=lxy&chs=100x100&chm=s,00FF00,0,-1,5&chd=t:";

            Assert.AreEqual(expected, result, "Url does not match");
        }

        [TestMethod]
        public void TestNotModifyingCasesDateTime()
        {
            CaseSet cs1 = new CaseSet();
            cs1.Levels.Add("type", 1);
            cs1.Levels.Add("type2", 2);
            cs1.Levels.Add("type3", 3);
            cs1.Date = DateTime.Now;

            CaseSet cs2 = new CaseSet();
            cs2.Levels.Add("type2", 1);
            cs2.Levels.Add("type3", 2);
            cs2.Levels.Add("type", 3);
            cs2.Date = DateTime.Now.AddDays(5);
            DateTime oldDate2 = cs2.Date;

            CaseSet cs3 = new CaseSet();
            cs3.Levels.Add("type4", 4);
            cs3.Levels.Add("type", 10);
            cs3.Levels.Add("type6", 6);
            cs3.Date = DateTime.Now.AddDays(2);
            DateTime oldDate3 = cs3.Date;

            caseSets.Add(cs2);
            caseSets.Add(cs1);
            caseSets.Add(cs3);

            int x;
            CurveUrlGenerator.GetCurveChartUrl(100, 100, caseSets, "type", out x);

            Assert.AreEqual(cs2.Date, oldDate2, "Date 2 not equal!");
            Assert.AreEqual(cs3.Date, oldDate3, "Date 2 not equal!");
        }

        [TestMethod]
        public void TestNotEmpty()
        {
            CaseSet cs1 = new CaseSet();
            cs1.Levels.Add("type", 1);
            cs1.Levels.Add("type2", 2);
            cs1.Levels.Add("type3", 3);
            cs1.Date = DateTime.Now;

            CaseSet cs2 = new CaseSet();
            cs2.Levels.Add("type2", 1);
            cs2.Levels.Add("type3", 2);
            cs2.Levels.Add("type", 3);
            cs2.Date = DateTime.Now.AddDays(45);

            CaseSet cs3 = new CaseSet();
            cs3.Levels.Add("type4", 4);
            cs3.Levels.Add("type", 10);
            cs3.Levels.Add("type6", 6);
            cs3.Date = DateTime.Now.AddDays(2);

            caseSets.Add(cs2);
            caseSets.Add(cs1);
            caseSets.Add(cs3);

            int x;
            var result = CurveUrlGenerator.GetCurveChartUrl(400, 200, caseSets, "type", out x);
            var expected = "http://chart.apis.google.com/chart?cht=lxy&chs=400x200&chm=s,00FF00,0,-1,5&chd=t:0,2,45|1,10,3&chxt=y,x&chxl=1:|";
            expected += "4/28/2009|5/18/2009|6/7/2009|6/27/2009|7/17/2009|8/6/2009";
            expected += "&chg=20,20";
            expected += "&chds=0,100,0,10&chxr=0,0,10";

            Assert.AreEqual(expected, result, "Url does not match. If today is not 4/28/2009 this test needs to change expected value to work anyway");
        }
    }
}
